#ifndef _PORT_LCD_H
#define _PORT_LCD_H

//SPI GROUP MAP
#define SPI1MAP_G               SPI1MAP_G1

//LCD CMD PIN(A0)
#define LCD_CMD_INIT()          {GPIOADE |= BIT(2); GPIOADIR &= ~BIT(2); GPIOASET = BIT(2);}
#define LCD_CMD_EN()            {GPIOACLR = BIT(2);}
#define LCD_CMD_DIS()           {GPIOASET = BIT(2);}

//LCD RST PIN
#define LCD_RST_INIT()          {GPIOADE |= BIT(1); GPIOADIR &= ~BIT(1); GPIOASET = BIT(1);}
#define LCD_RST_SET()           {GPIOASET = BIT(1);}
#define LCD_RST_CLR()           {GPIOACLR = BIT(1);}

//LCD CS PIN
#define LCD_SPI_CS_INIT()       {GPIOADE |= BIT(0); GPIOADIR &= ~BIT(0); GPIOASET = BIT(0);}
#define LCD_SPI_CS_EN()         {GPIOACLR = BIT(0);}
#define LCD_SPI_CS_DIS()        {GPIOASET = BIT(0);}

#define LCD_SPI_CLK_INIT()      {GPIOAFEN |= BIT(3); GPIOADE |= BIT(3); GPIOADIR &= ~BIT(3); GPIOASET = BIT(3);}
#define LCD_SPI_DAT_INIT()      {GPIOAFEN |= BIT(4); GPIOADE |= BIT(4); GPIOADIR |= BIT(4); GPIOAPU |= BIT(4);}

#define LCD_BACKLIGHT_INIT()    {GPIOADE |= BIT(5); GPIOADIR &= ~BIT(5); GPIOASET = BIT(5);}
#define LCD_BACKLIGHT_ON()      {GPIOASET = BIT(5);}
#define LCD_BACKLIGHT_OFF()     {GPIOACLR = BIT(5);}


void lcd_spi_init(void);

    #define LCD_WIDTH               240
    #define LCD_HEIGHT              320

    #define COLUMN_MAX              LCD_WIDTH           //屏的列数
    #define LINE_MAX                320        //屏的行数


    //指令宏定义
    #define X_Col_Addr     0x80		//定位到第0列指令(列起始地址)(0 - 83)
    #define Y_Page_Addr    0x40		//定位到第0页指令(页起始地址)(0 - 5)

void lcd_init(void);
/*--------------------------------------------------------------*/
//液晶字节定位(1*1)
//液晶规划:
//x: 0 - 83
//y: 0 - 5
void LCD_pos_byte(unsigned char x, unsigned char y);


/*--------------------------------------------------------------*/
//液晶字符输出(8*16字体)
//x: 0 - 9
//y: 0 - 2
void LCD_printc(unsigned char x, unsigned char y, unsigned char c_dat);


/*--------------------------------------------------------------*/
//液晶字符串输出(8*16字体)
//x: 0 - 9
//y: 0 - 2
void LCD_prints(unsigned char x, unsigned char y,  char  *s_dat);

/*The LCD needs a bunch of command/argument values to be initialized. They are stored in this struct. */
typedef struct {
    uint8_t cmd;
    uint8_t data[16];
    uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
} lcd_init_cmd_t;
#endif // _PORT_LCD_H
